<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<title>Fill comparing table</title>
</head>
<body>
<div class="container">
	<h1>Fill the decision table</h1>
	<h1>Please, fill only above half of the table, the other half will
		fill automatically</h1>

	<form:form method="POST" commandName="tableForm"
		action="${pageContext.request.contextPath}/table-group/create">

		<h1>Compare groups between each other</h1>
		<c:set var="main_index" scope="session" value="${0}"/> 
		<table border="1">

			<form:select path="tableList[${main_index}].operation">
				<form:options items="${tableList[main_index].operation}" />
			</form:select>
			<tbody>
				<tr>
					<th></th>
					<c:forEach var="group" items="${groups}">
						<th>${group.name}</th>
					</c:forEach>

				</tr>
				<c:forEach var="group" items="${groups}" varStatus="i">
					<tr>
						<td>${group.name}</td>
						<c:forEach var="group2" items="${groups}" varStatus="j">

							<c:choose>
								<c:when test="${i.index > j.index }">
									<td><input type="text"
										name="tableList[${main_index}].table[${i.index}][${j.index}]"
										value="0,0,0" readonly="true" /></td>
								</c:when>

								<c:when test="${i.index == j.index }">
									<td><input type="text"
										name="tableList[${main_index}].table[${i.index}][${j.index}]"
										value="1,1,1" readonly="true" /></td>
								</c:when>

								<c:when test="${i.index != j.index }">
									<td><form:input
											path="tableList[${main_index}].table[${i.index}][${j.index}]" /></td>
								</c:when>
							</c:choose>
						</c:forEach>

					</tr>

				</c:forEach>

			</tbody>
		</table>
		<br />
		<form:errors path="tableList[${main_index}]" cssStyle="color: red;" />
		<br />
		<c:set var="main_index" scope="session" value="${main_index + 1}"/> 




		<c:forEach var="group" items="${groups }" varStatus="k">

			<h1>Compare criteria for group: "${group.name }"</h1>

			<table border="1">

				<form:select path="tableList[${main_index}].operation">
					<form:options items="${tableList[main_index].operation}" />
				</form:select>
				<tbody>
					<tr>
						<th></th>
						<c:forEach var="cr_name" items="${criteriaForGroup[k.index]}">
							<th>${cr_name.name}</th>
						</c:forEach>

					</tr>
					<c:forEach var="cr_name" items="${criteriaForGroup[k.index]}"
						varStatus="i">
						<tr>
							<td>${cr_name.name}</td>
							<c:forEach var="cr_name1" items="${criteriaForGroup[k.index]}"
								varStatus="j">

								<c:choose>
									<c:when test="${i.index > j.index }">
										<td><input type="text"
											name="tableList[${main_index}].table[${i.index}][${j.index}]"
											value="0,0,0" readonly="true" /></td>
									</c:when>

									<c:when test="${i.index == j.index }">
										<td><input type="text"
											name="tableList[${main_index}].table[${i.index}][${j.index}]"
											value="1,1,1" readonly="true" /></td>
									</c:when>

									<c:when test="${i.index != j.index }">
										<td><form:input
												path="tableList[${main_index}].table[${i.index}][${j.index}]" /></td>
									</c:when>
								</c:choose>
							</c:forEach>

						</tr>

					</c:forEach>

				</tbody>
			</table>
			<br />
			<form:errors path="tableList[${main_index}]" cssStyle="color: red;" />
			<c:set var="main_index" scope="session" value="${main_index + 1}"/>
			<br />
		
		
			<c:forEach var="cr_name" items="${criteriaForGroup[k.index]}" varStatus="t">

				<h1>Compare companies for criterion "${cr_name.name }" group "${group.name }" </h1>

				<table border="1">

					<form:select path="tableList[${main_index}].operation">
						<form:options items="${tableList[main_index].operation}" />
					</form:select>
					<tbody>
						<tr>
							<th></th>
							<c:forEach var="firm" items="${firms}">
								<th>${firm.name}</th>
							</c:forEach>

						</tr>
						<c:forEach var="firm" items="${firms}" varStatus="i">
							<tr>
								<td>${firm.name}</td>
								<c:forEach var="firm1" items="${firms}" varStatus="j">

									<c:choose>
										<c:when test="${i.index > j.index }">
											<td><input type="text"
												name="tableList[${main_index}].table[${i.index}][${j.index}]"
												value="0,0,0" readonly="true" /></td>
										</c:when>

										<c:when test="${i.index == j.index }">
											<td><input type="text"
												name="tableList[${main_index}].table[${i.index}][${j.index}]"
												value="1,1,1" readonly="true" /></td>
										</c:when>

										<c:when test="${i.index != j.index }">
											<td><form:input
													path="tableList[${main_index}].table[${i.index}][${j.index}]" /></td>
										</c:when>
									</c:choose>
								</c:forEach>

							</tr>

						</c:forEach>

					</tbody>
				</table>
				<br />
				<form:errors path="tableList[${main_index}]" cssStyle="color: red;" />
				<c:set var="main_index" scope="session" value="${main_index + 1}"/>
				<br />

			</c:forEach>

		</c:forEach>

		<input type="submit" value="Calculate" />
	</form:form>
	<a href="${pageContext.request.contextPath}/">Home page</a>
</div>
</body>
</html>